package com.amap.map3d.demo

import android.Manifest
import android.app.Notification
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.location.LocationManager
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.PowerManager
import android.util.Log
import android.view.View
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import com.amap.api.location.AMapLocationClient
import com.amap.api.location.AMapLocationClientOption
import com.amap.api.maps.MapView
import com.amap.api.maps.MapsInitializer
import com.amap.api.maps.offlinemap.OfflineMapActivity
import com.amap.api.maps.offlinemap.OfflineMapManager
import com.amap.map3d.demo.R.id.mapview

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        MapsInitializer.updatePrivacyShow(applicationContext,true,true)
        MapsInitializer.updatePrivacyAgree(applicationContext,true)
        MapsInitializer.setTerrainEnable(true)
        val checkSelfPermission = checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
        Log.e("TAG", "onCreate: ${checkSelfPermission}")
        if (checkSelfPermission != 0) {
            val shouldShowRequestPermissionRationale = ActivityCompat.shouldShowRequestPermissionRationale(
                this, Manifest.permission.ACCESS_FINE_LOCATION)
            Log.e("TAG", "onCreate: ${shouldShowRequestPermissionRationale}")
            requestPermissions(arrayOf(
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION,
            ), 100)
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            requestPermissions(arrayOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION), 100)
        }
        AMapLocationClient.updatePrivacyShow(this, true, true)
        AMapLocationClient.updatePrivacyAgree(this, true)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            startForegroundService(Intent(this, LocationService::class.java))
        } else {
            startService(Intent(this, LocationService::class.java))
        }

    }

    fun offline(view: View) {
        startActivity(Intent(this, OfflineMapActivity::class.java))
    }

    fun map(view: View) {
        startActivity(Intent(this, MainActivity2::class.java))
    }

}